package com.ruoyi.project.game.recommendhistory.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.framework.aspectj.lang.annotation.DataSource;
import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;
import com.ruoyi.project.game.game.domain.Game;
import com.ruoyi.project.game.game.mapper.GameMapper;
import com.ruoyi.project.game.recommendhistory.domain.RecommendHistory;
import com.ruoyi.project.game.recommendhistory.mapper.RecommendHistoryMapper;
import com.ruoyi.project.game.recommendhistory.service.IRecommendHistoryService;

/**
 * 热搜设置Service业务层处理
 * 
 * @author shixiangwen
 * @date 2020-02-24
 */
@Service
@DataSource(value = DataSourceType.GAME)
public class RecommendHistoryServiceImpl implements IRecommendHistoryService {

	@Autowired
	private RecommendHistoryMapper recommendHistoryMapper;

	@Autowired
	private GameMapper gameMapper;

	/**
	 * 查询热搜设置
	 * 
	 * @param id 热搜设置ID
	 * @return 热搜设置
	 */
	@Override
	public RecommendHistory selectRecommendHistoryById(Long id) {
		return recommendHistoryMapper.selectRecommendHistoryById(id);
	}

	/**
	 * 查询热搜设置列表
	 * 
	 * @param recommendHistory 热搜设置
	 * @return 热搜设置
	 */
	@Override
	public List<RecommendHistory> selectRecommendHistoryList(RecommendHistory recommendHistory) {
		List<RecommendHistory> list = recommendHistoryMapper.selectRecommendHistoryList(recommendHistory);
		for (RecommendHistory history : list) {
			Game game = gameMapper.selectGameById(history.getGameId());
			if (game != null) {
				history.setName(game.getName());
				history.setIcon(game.getIcon());
			}
		}
		return list;
	}

	/**
	 * 新增热搜设置
	 * 
	 * @param recommendHistory 热搜设置
	 * @return 结果
	 */
	@Override
	public int insertRecommendHistory(RecommendHistory recommendHistory) {
		recommendHistory.setCreateTime(DateUtils.getNowDate());
		return recommendHistoryMapper.insertRecommendHistory(recommendHistory);
	}

	/**
	 * 修改热搜设置
	 * 
	 * @param recommendHistory 热搜设置
	 * @return 结果
	 */
	@Override
	public int updateRecommendHistory(RecommendHistory recommendHistory) {
		recommendHistory.setUpdateTime(DateUtils.getNowDate());
		return recommendHistoryMapper.updateRecommendHistory(recommendHistory);
	}

	/**
	 * 删除热搜设置对象
	 * 
	 * @param ids 需要删除的数据ID
	 * @return 结果
	 */
	@Override
	public int deleteRecommendHistoryByIds(String ids) {
		return recommendHistoryMapper.deleteRecommendHistoryByIds(Convert.toStrArray(ids));
	}

	/**
	 * 删除热搜设置信息
	 * 
	 * @param id 热搜设置ID
	 * @return 结果
	 */
	@Override
	public int deleteRecommendHistoryById(Long id) {
		return recommendHistoryMapper.deleteRecommendHistoryById(id);
	}
}
